<% layout('layout/layout') %>
<% block('header').append(`<style>
</style>`) %>
<div class="container">

  <ol class="breadcrumb">
    <li><a href="/">首页</a></li>
    <li class="active"><%= title %></li>
  </ol>
  <div class="section text-center" style="padding:20px 180px;">
    <h1 class="amount " style="padding-bottom:40px;">￥<%= needPrice %></h1>
    <div id="qrcode"></div>
    <div style="margin-top:40px;border-top:1px dashed #e3e3e3;"></div>
    <div>
      <dl class="row" style="margin:20px auto;width:300px;">
        <dt class="col-xs-4">
          <i class="iconfont icon-scanning text-primary" style="font-size:46px;"></i>
        </dt>
        <dd class="text-left  col-xs-8 fs18" style="line-height:30px;">
          <span>请用<span class="text-primary">微信</span>扫一扫</span><br/>
          <span>扫描二维码完成支付</span>
        </dd>
      </dl>
    </div>
  </div>
</div>
<% block('footer').append('<script src="/js/jquery.qrcode.min.js"></script>') %>
<% block('footer').append(`<script>
 jQuery(function(){
 	  var url = '${code_url}'
 	  var orderId = '${order.orderId}'
 	  var id = '${order._id}'
 	  $('#qrcode').qrcode(url);
 	  function poll () {
 	  	$.ajax({
 	  	  url: '/order/isPay',
 	  	  type: 'POST',
 	  	  data: 'id='+id+'&orderId='+orderId,
 	  	  success: function (res) {
 	  	  	console.log(res)
 	  	  	if (res.data.result_code === 'SUCCESS' && 	res.data.trade_state === 'SUCCESS') {
             location.href='/order/success?id='+id
 	  	  	} else {
 	  	  		setTimeout(poll, 3000)
 	  	  	}
 	  	  },
 	  	  error: function () {
 	  	  	setTimeout(poll, 3000)
 	  	  }
 	  	})
 	  }
 	  setTimeout(poll, 5000)
//    setTimeout(function(){
//    	location.href='/order/success'
//    },5000)
 })
</script>`) %>